package org.example.mybatis.spring.jdbc;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 文件描述
 *
 * @author yezhou41127
 * @date: 2022年11月03日
 */
public class Query {

	public static void main(String[] args) throws ClassNotFoundException {
		//
		String url = "jdbc:mysql://localhost:13306/gin-server";
		String userName = "root";
		String password = "roottt";
		Class.forName("com.mysql.cj.jdbc.Driver");


	}

	private static void hikari(String url, String userName, String password) {
		HikariConfig hikariConfig = new HikariConfig();
		hikariConfig.setJdbcUrl(url);
		hikariConfig.setUsername(userName);
		hikariConfig.setPassword(password);
//		hikariConfig.setAutoCommit(false);


		try (HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
			 Connection connection = hikariDataSource.getConnection();
			 Statement statement = connection.createStatement();
			 ResultSet resultSet = statement.executeQuery("select  * from user_info")) {
			while (resultSet.next()) {
				System.out.println(resultSet.getString(5));
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	private static void jdbc(String url, String userName, String password) {
		try (Connection connection = DriverManager.getConnection(url, userName, password);
			 Statement statement = connection.createStatement();
			 ResultSet resultSet = statement.executeQuery("select  * from user_info")) {
			while (resultSet.next()) {
				System.out.println(resultSet.getString(5));
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

}
